package ska

import (
	"sync"

	"gddgame.cc/galaxy/utils/def"
	"github.com/sirupsen/logrus"
)

// 日志服务

type Engine interface {
	SetDebug(flag bool)

	Register(field string, recorder def.Recorder)
}

type engine struct {
	logger *logrus.Logger
	debug  bool

	recorderMap sync.Map
}

func NewEngine(logger *logrus.Logger) Engine {
	e := &engine{
		logger:      logger,
		debug:       false,
		recorderMap: sync.Map{},
	}
	return e
}

func (e *engine) SetDebug(flag bool) {
	e.debug = flag
}

func (e *engine) Register(field string, recorder def.Recorder) {
	hook := &topicHook{
		field:    field,
		Recorder: recorder,
	}
	e.logger.AddHook(hook)
}
